package HibernateOrederManagement.app;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import HibernateOrderManagerment.bean.SendStatus;

public class SendStatusDao {
	private Session session;
	public SendStatusDao(Session session){
		this.session=session;
	}
	public List<SendStatus> list(){
		Query<SendStatus> query=session.createQuery("from SendStatus",SendStatus.class);
		return query.getResultList();
	}
	public SendStatus getSendStatusById(long id) {
		return session.get(SendStatus.class, id);
	}
	public SendStatus getByCode(String code){
		Query<SendStatus> query =session.createQuery("from SendStatus where code=:code",SendStatus.class);
		query.setParameter("code", code);
		return query.getSingleResult();
	}
	public SendStatus getByName(String name){
		Query<SendStatus> query =session.createQuery("from SendStatus where name=:name",SendStatus.class);
		query.setParameter("name", name);
		return query.getSingleResult();
	}
	public SendStatus listByDescription(String description){
		Query<SendStatus> query =session.createQuery("from SendStatus where description=:description",SendStatus.class);
		query.setParameter("description", description);
		return query.getSingleResult();
	}
	public void insert(SendStatus sendStatus) {
		Transaction tx = session.beginTransaction();
		try {

			session.save(sendStatus);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
	}
	public void update(SendStatus   sendStatus){
		Transaction tx = session.beginTransaction();
		try {

			session.update( sendStatus);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}
	public void delete(SendStatus  sendStatus){
		Transaction tx = session.beginTransaction();
		try {
			
			session.delete( sendStatus);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}

}
